<template>
  <div class="_mbbox boxgap">
    <div class="nbox2 bg5">
      非专武只计算本专队伍暴击率 / 队员暴率按4人计算 / 属性专属暴率按4人计算 /
      连锁临时暴率不算 / 部分角色未录入 【特殊情况自己手动脑算】
    </div>
    <div class="nbox1">
      <m-role
        :ban="['ghz']"
        :maxlimit="4"
        showsp
        showwepon
        showyw
        showmk
        showywlx
        :data="val.role"
      ></m-role>
      <div
        class="flex g8 bg5 pd2"
        style="width: 300px; margin: 0 auto; flex-direction: column; align-items: center"
      >
        <div v-for="(item, key) in val.role">
          <template v-if="cfg?.role_icon?.[item.i]?.br_bjl1 == null && item.i != null"
            >（角色未设置暴击率，请等待管理员收录或脑算）</template
          >
          <template v-if="item.i != null">
            [{{ cfg.role_icon[item?.i]?.bname[0] }}] 暴击率
            {{ set.sum(item, key) }}%</template
          >
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { cfg } from "@/cfg/cfg.js";
import { getrole } from "@/cfg/function.js";
import { set } from "lodash";
export default {
  props: {},
  setup() {
    const set = {
      ssb: {
        手镯: 10,
        牛头: 5,
        魔镜: 0,
      },
      c: {
        暴暴: 6,
        暴攻: 3,
        技暴: 3,
        暴暴暴: 9,
        暴暴攻: 6,
        暴攻攻: 3,
      },
      yl: {
        杯子: 10,
      },
      dz: (key) => {
        if (key != 0) {
          return 0;
        }
        let tbj = 0;
        for (let index = 0; index < val.role.length; index++) {
          const element = val.role[index];
          if (element.i == null) {
            continue;
          }
          const role = cfg.role_icon[element.i];
          if (role.ld_bjl1 != null) {
            tbj += parseInt(role.ld_bjl1 ?? 0);
          }
        }
        return tbj;
      },
      zbj: (key) => {
        let tbj = 0;
        for (let index = 0; index < val.role.length; index++) {
          const element = val.role[index];
          if (element.i == null) {
            continue;
          }
          const role = cfg.role_icon[element.i];

          if (element.w == "本专") {
            if (role.tm_bjl1 != null) {
              tbj += parseInt(role.tm_bjl1 ?? 0);
            }
          } else {
            if (element.w == "二专") {
              if (role.tm_bjl2 != null) {
                tbj += parseInt(role.tm_bjl2 ?? 0);
              }
            } else {
              if (role.tm_bjl1 != null) {
                tbj += parseInt(role.tm_bjl1 ?? 0);
              }
            }
          }
        }
        return tbj;
      },
      sum: (item, key) => {
        let sum = 0;

        const i = parseInt(cfg.role_icon[item.i]?.br_bjl1 ?? 0);
        sum += i;
        if (item.w == "本专") {
          if (cfg.role_icon[item.i]?.zw_bjl1 != null) {
            const zw = parseInt(cfg.role_icon[item.i]?.zw_bjl1 ?? 0);
            sum += zw;
          }
        } else {
          if (item.w == "二专") {
            if (cfg.role_icon[item.i]?.zw_bjl2 != null) {
              const zw = parseInt(cfg.role_icon[item.i]?.zw_bjl2 ?? 0);
              sum += zw;
            }
          }
        }
        if (item.s != null) {
          const s = parseInt(set.ssb[item.s] ?? 0);
          sum += s;
        }

        sum += set.zbj();
        sum += set.dz(key);

        if (item.c != null) {
          const c = parseInt(set.c[item.c] ?? 0);
          sum += c;
        }
        if (item.yl != null) {
          const yl = parseInt(set.yl[item.yl] ?? 0);
          sum += yl;
        }
        if (item.y != null) {
          const y = parseInt(set.c[item.y] ?? 0);
          sum += y;
        }
        if (item.w == "二专") {
          if (cfg.role_icon[item.i]?.bl_bjl2 != null) {
            const zw = parseInt(cfg.role_icon[item.i]?.bl_bjl2 ?? 0);
            sum = sum * zw;
          }
        }
        return sum;
      },
    };
    const val = reactive({
      tmbj: 0,
      dzbj: 0,
      role: [
        { w: "本专", s: "牛头", c: "技技", y: "技技技", yl: "杯子" },
        { w: "本专", s: "手镯", c: "暴暴", y: "暴暴暴", yl: "杯子" },
        { w: "本专", s: "手镯", c: "暴暴", y: "暴暴暴", yl: "杯子" },
        { w: "本专", s: "手镯", y: "暴暴暴", yl: "杯子" },
      ],
    });

    onMounted(async () => {
      await getrole();
    });
    return {
      set,

      cfg,
      val,
    };
  },
};
</script>
